package com.example.demo.controller;

import com.example.demo.service.TeacherService;
import com.example.demo.vo.RespInfo;
import com.example.demo.vo.user.TeacherParam;
import com.example.demo.vo.user.TloginParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
    /**
     * 服务对象
     */
    @Resource
    private TeacherService teacherService;

    /**
     * 通过主键查询单条数据
     *
     * @param tid 主键
     * @return 单条数据
     */
    @GetMapping("/query/{tid}")
    public RespInfo queryByTid(@PathVariable("tid") Integer tid) {
        return teacherService.queryByTid(tid);
    }

    /**
     * 新增数据
     *
     * @param param 实体
     * @return 新增结果
     */
    @RequestMapping(value = "/add", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public RespInfo add(@RequestBody TeacherParam param) {
        return teacherService.insert(param);
    }

    /**
     * 编辑数据
     *
     * @param param 实体
     * @return 编辑结果
     */
    @RequestMapping(value = "/edit", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public RespInfo edit(@RequestBody TeacherParam param) {
        return teacherService.update(param);
    }

    /**
     * 删除数据
     *
     * @param tid 主键
     * @return 删除是否成功
     */
    @GetMapping("/del/{tid}")
    public RespInfo deleteByTid(@PathVariable("tid") Integer tid) {
        return teacherService.deleteByTid(tid);
    }


    /**
     * 用户登录
     */
    @RequestMapping(value = "/Tlogin", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public RespInfo Tlogin(@RequestBody TloginParam param) {
        return teacherService.Tlogin(param);
    }

}

